﻿<%@ Page Title="" Language="C#" MasterPageFile="~/WithoutPermBasic.Master" AutoEventWireup="true" CodeBehind="StorageOutDetail.aspx.cs" Inherits="StorageManage.UI.StorageOutDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function () {
            var height = $("#divTotal").height();
            var master = $("#master").height();
            var content = parseFloat(height) - parseFloat(master) - 30;
            $("#tbList").css("height", content);
            $('#TaskCode').combobox({
                valueFiled: 'value',
                textField: 'text',
                url: '/Logic/StorageIn.aspx?method=GetTaskCode',
                mode: 'remote',
                panelHeight: 200,
                required:true,
                onSelect: function (rec) {
                    if (rec!=undefined) {
                        com.ajax({
                            url: '/Logic/StorageIn.aspx?method=GetProjAndEng',
                            data: { taskCode: rec.text },
                            required: true,
                            success: function (data) {
                                $('#ProjName').val(data.projName);
                                $('#EngName').val(data.engName);
                            }
                        });
                    }
                    
                }

            });
            var url='/Logic/StorageOut.aspx?method=GetStorageOutDetial&ids=' + com.get.ids
            if (com.get.action=='edit') {
                url='/Logic/StorageOut.aspx?method=GetStorageOutDetial1&outCode=' + com.get.outCode
            }         
            com.ajax({
                url: url,
                success: function (data) {
                    console.log(data)
                    $('#form1').form('load', data.outMain);
                    $('#TaskCode').combobox('select', data.outMain.TaskCode)
                    $('#Warehouse').combobox('select', data.outMain.Warehouse)
                    $('#tbList').datagrid({
                        data:data.outList,
                        loadMsg: '数据加载中请稍候……',
                        rownumbers: true,
                        idField: "MaterialCode",
                        columns: [[
                            { field: 'ck', checkbox: true, width: 30 },
                            {
                                field: 'MaterialCode', title: '物料编码', width: 110, align: 'center',
                            },
                            { field: 'Name', title: '物料名称', width: 120, align: 'center', },
                            { field: 'Guige', title: '规格型号', width: 110, align: 'center', },
                            { field: 'Caizhi', title: '材质', width: 110, align: 'center', },
                            { field: 'CunHuoZhangNum', title: '存货张数', width: 70, align: 'center', },
                            { field: 'CunHuoWeight', title: '库存重量', width: 110, align: 'center', },
                            {
                                field: 'Length', title: '长(m)', width: 75, align: 'center',
                                formatter: function (value, row, index) {
                                    return "<input  id='Length' name='Length' value='" + value + "' style='width:65px'/>"
                                }
                            },
                            {
                                field: 'Width', title: '宽(m)', width: 75, align: 'center',
                                formatter: function (value, row, index) {
                                    return "<input  id='Width' name='Width' value='" + value + "' style='width:65px'/>"
                                }
                            },                           
                            {
                                field: 'OutZhangNum', title: '总支/张', width: 75, align: 'center',
                                formatter: function (value, row, index) {
                                    return "<input  id='OutZhangNum' name='OutZhangNum' value='" + value + "' style='width:65px;'/>";
                                },
                                styler: function (value, row, index) {
                                    if (value != '$') {
                                        return 'background-color:#ffee00;';                                  
                                    }
                                },
                            },
                            {
                                field: 'OutTotalWeight', title: '总重', width: 80, align: 'center',
                                formatter: function (value, row, index) {
                                    return "<input type='number'  id='OutTotalWeight' name='OutTotalWeight' value='" + value + "'  style='width:90px'/>";
                                },
                            },
                             {
                                 field: 'Mweight', title: '理论重量', width: 80, align: 'center',
                                 formatter: function (value, row, index) {
                                     return "<input  id='Mweight' name='Mweight' value='" + value + "' readonly='readonly' style='width:70px'/>";
                                 },
                             },
                              {
                                  field: 'MaterialType', title: '物料类型', width: 80, align: 'center',
                                  formatter: function (value, row, index) {
                                      return "<input  id='MaterialType' name='MaterialType' value='" + value + "' readonly='readonly' style='width:70px'/>";
                                  },
                              },
                        ]],
                        onLoadSuccess: function (data) {
                         
                            $('input[name=Length]').numberbox({
                                min: 0,
                                precision: 3,
                                onChange: function (newValue, oldValue) {
                                    $tr = $(this).closest('tr');
                                    var width = utils.ParseFloat($tr.find('#Width').numberbox('getValue'));
                                    var zhangNum = utils.ParseInt($tr.find('#OutZhangNum').numberbox('getValue'));
                                    var theoryWeight = utils.ParseFloat($tr.find('#Mweight').val());
                                    if (theoryWeight == undefined || theoryWeight == '') {
                                        theoryWeight = 0;
                                    }        
                                    var materialType = $tr.find('#MaterialType').val();
                                    console.log((utils.ParseFloat(newValue) * zhangNum * width * theoryWeight).toFixed(3))
                                    if (materialType.indexOf('板') > 0) {
                                        $tr.find('#OutTotalWeight').val((utils.ParseFloat(newValue) * zhangNum * width * theoryWeight).toFixed(3))
                                    } else if (materialType == '型材') {
                                        $tr.find('#OutTotalWeight').val((utils.ParseFloat(newValue) * zhangNum * theoryWeight / 1000).toFixed(3))
                                    }
                                }
                            });
                            $('input[name=Width]').numberbox({
                                min: 0,
                                precision: 3,
                                onChange: function (newValue,oldValue) {
                                    var length = utils.ParseFloat($tr.find('#Length').numberbox('getValue'));
                                    var zhangNum = utils.ParseInt($tr.find('#OutZhangNum').numberbox('getValue'));
                                    var theoryWeight = utils.ParseFloat($tr.find('#MWeight').val());
                                    if (theoryWeight == undefined || theoryWeight == '') {
                                        theoryWeight = 0;
                                    }
                                    var materialType = $tr.find('#MaterialType').val();
                                    if (materialType.indexOf('板') > 0) {
                                        $tr.find('#OutTotalWeight').val((utils.ParseFloat(newValue) * zhangNum * length * theoryWeight).toFixed(3))
                                    }
                                }
                            });
                            $('input[name=OutZhangNum]').numberbox({
                                min: 0,
                                onChange: function (newValue, oldValue) {
                                    $tr = $(this).closest('tr');
                                    var index = $tr.attr('datagrid-row-index');
                                  
                                    var outZhangNum = data.rows[index].CunHuoZhangNum;
                                    if (newValue > outZhangNum) {
                                        newValue = outZhangNum;
                                        $(this).numberbox('setValue',newValue)
                                        com.message('information', '出库量不能大于存货量')                                        
                                    }
                                    var length = utils.ParseFloat($tr.find('#Length').numberbox('getValue'));

                                    var width = utils.ParseFloat($tr.find('#Width').numberbox('getValue'));
                                    var theoryWeight = utils.ParseFloat($tr.find('#Mweight').val());
                                    if (theoryWeight == undefined || theoryWeight == '') {
                                        theoryWeight = 0;
                                    }
                                    var materialType = $tr.find('#MaterialType').val();
                                    if (materialType.indexOf('板') > 0) {
                                        $tr.find('#OutTotalWeight').val((utils.ParseFloat(newValue) * length * width * theoryWeight).toFixed(3))
                                    } else if (materialType == '型材') {
                                        $tr.find('#OutTotalWeight').val((utils.ParseFloat(newValue) * length * theoryWeight / 1000).toFixed(3))
                                    }
                                  
                                }
                            });
                        }
                    });
                }
            });
           
           

        });
    </script>
    <script type="text/javascript">
        function funcSave() {
            var form = com.serializeObj('form1');
            var rows = $('#tbList').datagrid('getRows');
            for (var i = 0; i < rows.length; i++) {
                $tr = $('#divTotal .datagrid-view2 .datagrid-body').find('tr').eq(i);
                rows[i].Length = $tr.find('#Length').numberbox('getValue');
                rows[i].Width = $tr.find('#Width').numberbox('getValue');
                rows[i].ZhangWeight = $tr.find('#ZhangWeight').val();
                rows[i].OutZhangNum = $tr.find('#OutZhangNum').numberbox('getValue');
                rows[i].OutTotalWeight = $tr.find('#OutTotalWeight').val();
            }
            $.extend(form, { info: JSON.stringify(rows) });
            var url='/Logic/StorageOut.aspx?method=AddStorageOut'
            if (com.get.action=="edit") {
                url='/Logic/StorageOut.aspx?method=EditStorageOut'
            }
            com.ajax({
                url: url,
                data: form,
                success: function (data) {
                    if (data.state=="success") {
                        com.message('information', data.msg);
                        window.location.href = '/UI/StorageOut.aspx';                                            
                    }
                }
            });
        }
        function funcAdd() {
            var ids = "";
            var outCode = "";
            if (com.get.action == "edit") {
                ids = '0';
                outCode = $('#OutCode').val();
            }else {
                ids=com.get.ids;
            }
            window.location.href = '/UI/Storage.aspx?action=addOutDetail&ids=' + ids+"&outCode="+outCode;
        }
        function funcRemove() {
            var rows = $('#tbList').datagrid('getSelections');
            for (var i = 0; i < rows.length; i++) {
                var index=$('#tbList').datagrid('getRowIndex', rows[i]);
                $('#tbList').datagrid('deleteRow', index);
            }
            com.message('information','删除条目成功')
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceToorbar" runat="server">
    <a href="javascript:void(0)" id="btnSave" class="easyui-linkbutton" onclick="funcSave()"
        data-options="iconCls:'icon-save'">保存</a>
    <a href="javascript:void(0)" id="btnAdd " class="easyui-linkbutton" onclick="funcAdd()"
        data-options="iconCls:'icon-add'">插入条目</a>
    <a href="javascript:void(0)" id="brnRemove " class="easyui-linkbutton" onclick="funcRemove()"
        data-options="iconCls:'icon-remove'">删除条目</a>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <div id="divTotal" style="height:100%;width:100%">
         <div id="master" style="height: auto;width:100%">
             <form id="form1">
                  <table style="width:100%">
                    <tr >
                        <th colspan="8">
                            <h1>生产出库单</h1>
                        </th>
                    </tr>
                    <tr>
                        <th colspan="8">
                                <hr />
                        </th>
                    </tr>
                    <tr>
                        <td style="text-align:right;">出库单号：</td>
                        <td>
                            <input type="text" name="OutCode" id="OutCode" style="border:none;" readonly="readonly" />
                        </td>
                         <td style="text-align:right;">制单人：</td>
                        <td> 
                            <input type="text" name="ApplyPerson" id="ApplyPerson"  style="border:none;" readonly="readonly"/>
                        </td>
                         <td style="text-align:right;">制单时间：</td>
                        <td>
                            <input type="text" name="ApplyTime" id="ApplyTime"  style="border:none;"  readonly="readonly"/>
                        </td>
                         <td style="text-align:right;">领料班组：</td>
                        <td>
                            <input id="OutTeam" name="OutTeam" class="easyui-combobox" data-options="valueField:'text',textField:'text',url:'/Logic/StorageIn.aspx?method=GetTeam',panelHeight:'200',mode:'remote'," />
                        </td>
                    </tr>

                    <tr>
                        <td style="text-align:right;">生产制号：</td>
                        <td>
                            <input type="text" name="TaskCode" id="TaskCode" />
                        </td>
                         <td style="text-align:right;">项&nbsp;&nbsp;&nbsp;&nbsp;目：</td>
                        <td>
                            <input type="text" name="ProjName" id="ProjName" readonly="readonly" />
                        </td>
                         <td style="text-align:right;">工&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;程：</td>
                        <td>
                            <input type="text" name="EngName" id="EngName" readonly="readonly" />
                        </td>
                         <td style="text-align:right;">仓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;库：</td>
                        <td>
                             <input type="text" name="Warehouse" id="Warehouse"  class="easyui-combobox" data-options="valueField:'text',textField:'text',url:'/Logic/BasicInfo.aspx?method=GetWarehouse',panelHeight:'200',required:'true'," />
                        </td>
                    </tr>
                    <tr>
                         <td style="text-align:right;">领&nbsp;&nbsp;料&nbsp;&nbsp;人：</td>
                        <td>
                            <input type="text" name="OutPerson" id="OutPerson" class="easyui-combobox" data-options="valueField:'text',textField:'text',url:'/Logic/BasicInfo.aspx?method=GetOutPerson',panelHeight:'200',required:'true'" />
                        </td>
                        <td style="text-align:right;">备&nbsp;&nbsp;&nbsp;&nbsp;注：</td>
                <td ">
                    <input type="text" name="Note" id="Note" style="width:200px;" />
                </td>
                    </tr>
                </table>
             </form>
         </div>
         <table id="tbList" title="余料出库表" style="width:100%"  >
        </table>
    </div>
</asp:Content>
